package com.www.applyword.ui.chat;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.tencent.imsdk.TIMFriendshipManager;
import com.tencent.imsdk.TIMUserProfile;
import com.tencent.imsdk.TIMValueCallBack;
import com.tencent.imsdk.friendship.TIMFriendPendencyItem;
import com.tencent.imsdk.friendship.TIMFriendPendencyRequest;
import com.tencent.imsdk.friendship.TIMFriendPendencyResponse;
import com.tencent.imsdk.friendship.TIMPendencyType;
import com.tencent.qcloud.tim.uikit.component.TitleBarLayout;
import com.www.applyword.R;
import com.www.applyword.adapter.NewFriendListAdapter;
import com.www.applyword.base.BaseActivity;
import com.www.applyword.utils.Utils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * author : huang
 * date   : 2019/11/16 0016 11:38
 * version: 1.0
 */
public class NewFriendActivity extends BaseActivity {
    private static final String TAG = NewFriendActivity.class.getSimpleName();
    @BindView(R.id.ll_new_friends)
    LinearLayout llNewFriends;

    private TitleBarLayout mTitleBar;
    private ListView mNewFriendLv;
    //   private NewFriendListAdapter mAdapter;
    private TextView mEmptyView;
    private List<TIMFriendPendencyItem> mList = new ArrayList<>();
    private  List<String> identifiers = new ArrayList<>();
    private NewFriendListAdapter mAdapter;
    private List<TIMUserProfile> timUserProfiles2 = new ArrayList<>();

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.contact_new_friend_activity);
        setTitle("新的联系人");
        initView();
    }

    private void initView() {
       // mTitleBar = findViewById(R.id.new_friend_titlebar);
      //  mTitleBar.setTitle(getResources().getString(R.string.new_friend), TitleBarLayout.POSITION.LEFT);
        mNewFriendLv = findViewById(R.id.new_friend_list);
        mEmptyView = findViewById(R.id.empty_text);
    }

    @Override
    protected void loadData() {
        final TIMFriendPendencyRequest timFriendPendencyRequest = new TIMFriendPendencyRequest();
        timFriendPendencyRequest.setTimPendencyGetType(TIMPendencyType.TIM_PENDENCY_COME_IN);
        timFriendPendencyRequest.setSeq(0);
        timFriendPendencyRequest.setTimestamp(0);
        timFriendPendencyRequest.setNumPerPage(10);
        TIMFriendshipManager.getInstance().getPendencyList(timFriendPendencyRequest, new TIMValueCallBack<TIMFriendPendencyResponse>() {
            @Override
            public void onError(int i, String s) {
                Utils.showToastSafe("Error code = " + i + ", desc = " + s);
            }

            @Override
            public void onSuccess(TIMFriendPendencyResponse timFriendPendencyResponse) {
                if (timFriendPendencyResponse.getItems() != null) {
                    if (timFriendPendencyResponse.getItems().size() == 0) {
                        mEmptyView.setText(getResources().getString(R.string.no_friend_apply));
                        mNewFriendLv.setVisibility(View.GONE);
                    //    mEmptyView.setVisibility(View.VISIBLE);
                        showEmpty(true,vsEmpty,3);
                        return;
                    }
                }


                mNewFriendLv.setVisibility(View.VISIBLE);
                mList.clear();
                mList.addAll(timFriendPendencyResponse.getItems());
              /*  for (TIMFriendPendencyItem timFriendPendencyItem : mList) {
                    identifiers.clear();
                    identifiers.add(timFriendPendencyItem.getIdentifier());
                }*/

                mAdapter = new NewFriendListAdapter(NewFriendActivity.this, R.layout.contact_new_friend_item, mList);
                mNewFriendLv.setAdapter(mAdapter);
                mAdapter.notifyDataSetChanged();
            }
        });
    }



    @OnClick(R.id.ll_new_friends)
    public void onViewClicked() {
        Utils.startActivity(BookFriendsActivity.class);
    }
}
